﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Entity;
using BLL;


namespace Web.frontpage
{
    public partial class Third : System.Web.UI.Page
    {
        public string title="";
        public string Ntitle="";
        public string from="";
        public string pubTime="";
        public string content="";
        public string ContestContent="";
        public string ContestTask = "暂无竞赛安排";
        public string Award = "暂无获奖信息";
        public string ContestPic = "暂无图片";
        public string id;
        public string ContestId="";
        public string works = "暂无作品";
        public string StuSummary = "暂无获奖感言";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                id = Request.QueryString["Id"];
                if (!string.IsNullOrEmpty(Request.QueryString["ContestId"]))
                {
                    ContestId = Request.QueryString["ContestId"];
                    RequestCheck();
                }
                if (!string.IsNullOrEmpty(id))
                    RequestCheck();
                checkShow();
            }
            
        }
        /// <summary>
        /// 判断要显示的tab
        /// </summary>
        protected void checkShow()
        {
            string liNumber = Request.QueryString["number"];
            switch (liNumber)
            {
                case "1":
                    li_1.Attributes["Class"] = "current";
                    div_1.Attributes["Class"] = "";
                    break;
                case "2":
                    li_2.Attributes["Class"] = "current";
                    div_2.Attributes["Class"] = "";
                    break;
                case "3":
                    li_3.Attributes["Class"] = "current";
                    div_3.Attributes["Class"] = "";
                    break;
                case "4":
                    li_4.Attributes["Class"] = "current";
                    div_4.Attributes["Class"] = "";
                    break;
                case "5":
                    li_5.Attributes["Class"] = "current";
                    div_5.Attributes["Class"] = "";
                    break;
                case "6":
                    li_6.Attributes["Class"] = "current";
                    div_6.Attributes["Class"]="";
                    break;
                default:
                    li_1.Attributes["Class"] = "current";
                    div_1.Attributes["Class"] = "";
                    break;
            }
        }
        /// <summary>
        /// 通过request的类别来获得相应的内容的行数
        /// </summary>
        /// <returns></returns>
        protected void RequestCheck()
        {
            BLL.NewsContent news= new BLL.NewsContent();
            BLL.ContestService contest = new BLL.ContestService();
            Entity.BoNewsContent model = new Entity.BoNewsContent();
            Entity.BoContests contestModel = new Entity.BoContests();
            StringBuilder sbd = new StringBuilder();
            switch (Request.QueryString["ClassId"])
            {
                case "0": //新闻公告
                    news_div.Style.Remove("display");
                    model  =  news.GetNewsSingle(id);
                    from = model.NewsAuthor;
                    pubTime = model.NewspubTime.ToString("yyyy/MM/dd");
                    content = model.NewsArticle;
                    Ntitle = model.NewsTitle;
                    title = "新闻公告";
                    break;
                //case "1": //新闻公告
                //    news_div.Style.Remove("display");
                //    contestModel = contest.GetV_Contest(id);
                //    Ntitle = contestModel.CON_NAME;
                //    sbd.Append("<dl style=\"border:1px solid #ccc;\">");
                //    sbd.Append("<dd>");
                //    sbd.Append("竞赛名称：<label>"+contestModel.CON_NAME+"</label>");
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("所属竞赛:<label>" + contestModel.Competitions.COM_NAME+ "</label>");
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("竞赛类别:<label>" + (contestModel.Competitions.COM_TYPE == 1 ? "省级" : "校级") + "</label>");    
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("报名形式：<label>"+(contestModel.Competitions.COM_FORM == 1 ? "小组报名" : "个人报名")+"</label>");    
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("竞赛年度：<label>" + contestModel.CON_YEAR.ToString() + "</label>");
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("竞赛月份：<label>"+contestModel.CON_MONTH.ToString()+"</label>");
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd >");
                //    sbd.Append("竞赛地点:<label>" + contestModel.CON_ADDRESS + "</label>");
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("指导教师：<label>"+contestModel.CON_TEACHERS+"</label>");
                //    sbd.Append("</dd>"); 
                //    sbd.Append("</dd>");
                //    sbd.Append("<dd>");
                //    sbd.Append("开始时间：<label>"+contestModel.CON_STARTTIME.ToString()+"</label> &nbsp;&nbsp;&nbsp;结束时间：<label>"+contestModel.CON_ENDTIME.ToShortDateString()+"</label>");
                //    sbd.Append("</dd>");  
                //    sbd.Append("<dd>");
                //    sbd.Append("创建人：<label>" + contestModel.CON_CREATOR + "</label>");
                //    sbd.Append("</dd>"); 
                //    sbd.Append("<dd>");
                //    sbd.Append("所属学院：<label>" + contestModel.ACA_NAME + "</label>");
                //    sbd.Append("</dd>"); 
                //    sbd.Append("</dl>");
                //    content = sbd.ToString();
                //    //pubTime = contestModel.;
                //    title = "竞赛通知";
                //    break;
                case "2": //校内竞赛
                    contest_div.Style.Remove("display");
                    GetContest();
                    //pubTime = contestModel.;
                    title = "校内竞赛";
                    break;
                case "3": //省级竞赛
                    contest_div.Style.Remove("display");
                    GetContest();
                    //pubTime = contestModel.;
                    title = "省级以上竞赛";
                    break;
                case "4": //管理制度
                    news_div.Style.Remove("display");
                    //ItemCount = (int)SQLHelper.GetRecordCount("NewsContent", "NewsClassId = '2'");
                    model  =  news.GetNewsSingle(id);
                    from = model.NewsAuthor;
                    pubTime = model.NewspubTime.ToString("yyyy/MM/dd");
                    Ntitle = model.NewsTitle;
                    content = model.NewsArticle;
                    title = "管理制度";
                    break;
                case "5": //下载中心
                    news_div.Style.Remove("display");
                    model  =  news.GetNewsSingle(id);
                    from = model.NewsAuthor;
                    pubTime = model.NewspubTime.ToString("yyyy/MM/dd");
                    Ntitle = model.NewsTitle;
                    content = model.NewsArticle;
                    title = "下载中心";
                    break;
                //case "6": //作品展示
                //    ItemCount = (int)SQLHelper.GetRecordCount("NewsContent", "NewsClassId = 15");
                //    break;
                case "7"://获得校内竞赛安排
                    contest_div.Style.Remove("display");
                    GetContest();
                    title = "校内竞赛安排";
                    break;
            }
        }
        /// <summary>
        /// 竞赛信息
        /// </summary>
        protected void GetContest()
        {
            BLL.ContestService contest = new BLL.ContestService();
            Entity.BoContests contestModel = new Entity.BoContests();
            StringBuilder sbd = new StringBuilder();
            contestModel = contest.GetV_Contest(ContestId);
            if (contestModel != null)
            {
                Ntitle = contestModel.CON_NAME;
                sbd.Append("<table cellspacing='1' bgcolor='#000'>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td colspan='6' align='center'><label>" + contestModel.CON_NAME + "</label></td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                //sbd.Append("所属竞赛:<label>" + contestModel.Competitions.COM_NAME + "</label>");
                sbd.Append("<td align='center' width='10%'>所属学院</td><td  width='20%'><label>" + contestModel.ACA_NAME + "</label></td>");
                sbd.Append("<td align='center' width='10%'>负责人</td><td width='20%'><label>" + contestModel.Competitions.COM_MANAGER + "</label></td>");
                sbd.Append("<td align='center' width='10%'>报名形式</td><td width='20%'><label>" + (contestModel.Competitions.COM_FORM == 1 ? "小组报名" : "个人报名") + "</label></td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td align='center' >开始时间</td><td><label>" + contestModel.CON_STARTTIME.ToShortDateString() + "</label> </td>");
                sbd.Append("<td align='center' >结束时间</td><td><label>" + contestModel.CON_ENDTIME.ToShortDateString() + "</label> </td>");
                sbd.Append("<td align='center' >竞赛地点</td><td><label>" + contestModel.CON_ADDRESS + "</label> </td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td align='center' >指导教师</td><td colspan='5' ><label>" + contestModel.CON_TEACHERS + "</label></td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td align='center' colspan='6'><a href='SignUp/login.aspx' class='red'>我要报名</a></td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td aligh='center' colspan='6'>竞赛内容介绍</td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='250px'bgcolor='#fff'>");
                sbd.Append("<td aligh='center' colspan='6'>"+ contestModel.COM_CONTENTS + "</td>");
                sbd.Append("</tr>");
                sbd.Append("</table>");

                getContestTarsk();
                getPhoto();
                GetWard();
                ContestContent = sbd.ToString();
                getStuSummary();
            }
        }
        /// <summary>
        /// 竞赛安排
        /// </summary>
        protected void getContestTarsk()
        {
            BLL.ContestService contest = new BLL.ContestService();
            StringBuilder sbd = new StringBuilder();
            BoContests contestModel = new BoContests() { CON_ID = ContestId };
            IList<BoProcedures> pro_models = contest.GetContestProcedures(contestModel);
           
    
            if (pro_models.Count > 0)
            {
               
                foreach (BoProcedures pro_model in pro_models)
                {
                    Ntitle = pro_model.CON_NAME;
                    sbd.Append("<table cellspacing='1' bgcolor='#000'>");
                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append("<td colspan='6' align='center'><label>" +  pro_model.CON_NAME + "</label></td>");
                    sbd.Append("</tr>");
                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append("<td align='center' width='10%'>竞赛阶段</td><td  width='20%'><label>" + pro_model.PHA_NAME + "</label></td>");
                    sbd.Append("<td align='center' width='10%'>负责人</td><td width='20%'><label>"+ pro_model.PRO_CONDUCTOR +"</label></td>");
                    sbd.Append("<td align='center' width='10%'>形式</td><td width='20%'><label>" + (contestModel.Competitions.COM_FORM == 1 ? "小组报名" : "个人报名") + "</label></td>");
                    sbd.Append("</tr>");

                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append("<td align='center' >开始时间</td><td><label>" + pro_model.PRO_STARTTIME.ToShortDateString() + "</label> </td>");
                    sbd.Append("<td align='center' >结束时间</td><td><label>" + contestModel.CON_ENDTIME.ToShortDateString() + "</label> </td>");
                    sbd.Append("<td align='center' >竞赛地点</td><td><label>" + pro_model.PRO_ENDTIME + "</label> </td>");
                    sbd.Append("</tr>");

                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append("<td aligh='center' colspan='6'>简介</td>");
                    sbd.Append("</tr>");


                    sbd.Append("<tr height='100px'bgcolor='#fff'>");
                    sbd.Append("<td aligh='center' colspan='6'>" + pro_model.PRO_CONTENT + "</td>");
                    sbd.Append("</tr>");
                    sbd.Append("</table>");


                   /* sbd.Append("<dl style=\"border:1px solid #ccc;\">");
                      sbd.Append("<dd>");
                      sbd.Append("竞赛安排：<label>" + pro_model.PHA_NAME + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("所属竞赛:<label>" + pro_model.CON_NAME + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("形式:<label>" + pro_model.PRO_METHOD + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("<dd >");
                      sbd.Append("地点:<label>" + pro_model.PRO_ADDRESS + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("负责人：<label>" + pro_model.PRO_CONDUCTOR + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("开始时间：<label>" + pro_model.PRO_STARTTIME + "</label> &nbsp;&nbsp;&nbsp;结束时间：<label>" + pro_model.PRO_ENDTIME + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("<dd>");
                      sbd.Append("简介：<label>" + pro_model.PRO_CONTENT + "</label>");
                      sbd.Append("</dd>");
                      sbd.Append("</dl>");*/
                }
                ContestTask = sbd.ToString();
            }
        }

        /// <summary>
        /// 获得获奖感言
        /// </summary>
        protected void getStuSummary()
        {
            ParticipantService participantService = new ParticipantService();
            StringBuilder sbd = new StringBuilder();
            IList<BoParticipants> participantModels = participantService.GetSummaryParticipantsByContest(ContestId);

            if (participantModels.Count > 0)
            {
                sbd.Append("<table cellspacing='1' width='100%'>");

                foreach (BoParticipants par in participantModels)
                {
                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append("<td width=\"25%\" height=\"18\">");
                    sbd.Append("<a href=\"StuSummary.aspx?Id=" + par.PAR_ID + "\">" + par.STU_NAME + "</a>");
                    sbd.Append("</td><td width=\"75%\" align=\"right\">");
                    sbd.Append("<a href=\"StuSummary.aspx?Id=" + par.PAR_ID + "\">" + par.PAR_SUMTITLE + "</a>");
                    sbd.Append("</td></tr>");
                }

                sbd.Append("</table>");
                StuSummary = sbd.ToString();
            }
         /*   if (participantModels != null) {
                Ntitle = "contestModel.CON_NAME;";
                sbd.Append("<table cellspacing='1' bgcolor='#000'>");
                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<td colspan='6' align='center'><label>" + participantModels.CON_NAME + "</label></td>");
                sbd.Append("</tr>");

                sbd.Append("<tr height='30px'bgcolor='#fff'>");
                sbd.Append("<th align='center' width='10%'>时间</th>");
                sbd.Append("<th align='center' width='10%'>学生</th>");
                sbd.Append("<th align='center' width='10%'>学号</th>");
                sbd.Append("<th align='center' width='10%'></th>");
                sbd.Append("</tr>");
                foreach (BoParticipants par in participantModels)
                {
                    sbd.Append("<tr height='30px'bgcolor='#fff'>");
                    sbd.Append(par.PAR_SUMTIME);
                    sbd.Append(par.STU_NAME);
                    sbd.Append(par.STU_NAME);
                    sbd.Append("<th align='center' width='10%'></th>");
                    sbd.Append("<td align='center' ><a href='' class='red'>获奖感言</a></td>");
                    sbd.Append("</tr>");
                }

                StuSummary = sbd.ToString();

            }*/

           //if(participantModels.Count>0)
           // {
           //     foreach(BoParticipants par in participantModels )
           //     {
                    

           //         sbd.Append("<br/>");
           //         sbd.Append("时间");
           //         sbd.Append(par.PAR_SUMTIME);
           //         sbd.Append("学生");
           //         sbd.Append(par.STU_NAME);
           //         sbd.Append("学号");
           //         sbd.Append(par.STU_NAME);
           //         sbd.Append("<br/>");
           //         sbd.Append(par.PAR_SUMMARY);
           //         sbd.Append("<a href=\"../UploadImages/");
           //         sbd.Append(par.PAR_SUMURL);                                      
           //         sbd.Append("</a>");
           //     }
           //     StuSummary = sbd.ToString(); 
           // }
           
        }

        /// <summary>
        /// 获得作品展示
        /// </summary>
        protected void getWorks()
        {
            BoWorks work = new BoWorks();
            WorkService workService = new WorkService();
            StringBuilder sbd = new StringBuilder();
            IList<BoWorks> workModels = workService.GetContestWorks(ContestId);
            if (workModels.Count > 0)
            {
                foreach (BoWorks wor in workModels)
                {                   

                    sbd.Append("<a href=\"../UploadImages/");
                    sbd.Append(wor.WOR_URL);
                    sbd.Append("\" rel=\"clearbox\" title=\"");
                    sbd.Append(wor.WOR_TITLE);
                    sbd.Append("\" ");
                    sbd.Append(">");
                    sbd.Append("<img class=\"l_img\" src=\"../UploadImages/");
                    sbd.Append(wor.WOR_URL);
                    sbd.Append("\" border='0' ");
                    sbd.Append("/>");
                    sbd.Append("</a>");
                }
                works = sbd.ToString();
            }
        }


        /// <summary>
        /// 获得竞赛图片
        /// </summary>
        protected void getPhoto()
        {
            BLL.PhotoService photo = new BLL.PhotoService();
            StringBuilder sbd = new StringBuilder();
            BoContests contestModel = new BoContests() { CON_ID = ContestId };
            IList<BoPhotos> photo_models = photo.GetContestPhotos(contestModel);
            if (photo_models.Count > 0)
            {
                foreach (BoPhotos photo_model in photo_models)
                {
                    sbd.Append("<a href=\"../UploadImages/");
                    sbd.Append(photo_model.PHO_URL);
                    sbd.Append("\" rel=\"clearbox\" title=\"");
                    sbd.Append(photo_model.PHO_TITLE);
                    sbd.Append("\" ");
                    sbd.Append(">");
                    sbd.Append("<img class=\"l_img\" src=\"../UploadImages/");
                    sbd.Append(photo_model.PHO_URL);
                    sbd.Append("\" border='0' ");
                    sbd.Append("/>");
                    sbd.Append("</a>");
                }
                ContestPic = sbd.ToString();
            }
        }
        /// <summary>
        /// 获得获奖信息
        /// </summary>
        protected void GetWard()
        {
            BLL.ParticipantService particepantservice = new BLL.ParticipantService();
            IList<BoParticipants>  particepantModels = particepantservice.getAwardsPar(ContestId);
            if (particepantModels.Count > 0)
            {
                StringBuilder sbd = new StringBuilder();
                sbd.Append("<dl>");
                var level = particepantModels.GroupBy(p => p.AWA_NAME).Select(p => p);
                foreach (var group in level)
                {
                    sbd.Append("<dt>");
                    sbd.Append(group.Key);
                    sbd.Append("</dt>");
                    sbd.Append("<dd>");
                    foreach (var name in group)
                    {
                        sbd.Append(name.STU_NAME);
                        sbd.Append(" ");
                    }
                    sbd.Append("</dd>");
                }
                sbd.Append("</dl>");
                Award = sbd.ToString();
            }
        }
    }
}